home *** CD-ROM | disk | FTP | other *** search
/ AGA Toolkit '97 / The AGA Toolkit '97.iso / rexxc / find.amiftp next >
Text File  |  1996-09-07  |  8KB  |  240 lines

  1. /* Find.AmiFTP for finding and downloading files from Aminet via TCP:
  2.  * Based on Browse.DaFTP by Osma Ahvenlampi and aminetfind.gvrexx by Josef Faulkner
  3.  *
  4.  * $VER: Find.AmiFTP 1.15 (11.3.96) by Sami Itkonen
  5.  * Usage:  find.AmiFTP [-e] ["substring"|"sub strings"] [-m<maxhits>] [-s<sitename>] [-p<portname]
  6.  *    [-f<findsite number>] [-w<width>] [-c<0|1>]
  7.  * Any of the arguments can be entered on the reqtools requester.
  8.  *
  9.  * Version history:
  10.  *
  11.  * 1.9 - Findsite didn't propagate from one script to another, fixed that bug
  12.  * 1.10 - All requesters/guide files now use the supplied public screen
  13.  * 1.11 - Changed the 'exact' keyword to the '-e' option
  14.  * 1.12 - Options can now be freely mixed in the command line.
  15.  *      - haegar2 (findsite) doesn't show age field, files found from there are now shown correctly 
  16.  * 1.13 - Added the viewmethod configuration option
  17.  * 1.14 - Added the view method 'builtin'
  18.  * 1.15 - Fixed the bug with the filtercrap
  19.     - You can now specify whether you want the crapfilter on or off with the -c option
  20.  */
  21.  
  22. /* START OF CONFIGURATION VARIABLES */
  23.  
  24. dldir = "ram:"             /* Your default downloading directory */
  25. AmiFTP_bin = "amiftp"     /* Full path to the AmiFTP binary */
  26. sitename = "ftp.uni-paderborn.de"    /* The default Aminet site you are using */
  27. pubscreen = "Workbench"            /* AmiFTP's public screen */
  28.  
  29. viewmethod = "none"   /* This variable defines the method to view files. If set to "builtin", it 
  30.                 uses AmiFTP's builtin VIEW command. If set to "processfile", it will use 
  31.                 'rexx:processfile.rexx'. Set it to anything else to disable file viewing. */
  32. filtercrap = 0             /* If this is set to 1, all crap will be filtered out, based on the
  33.                 filterpat variable, which contains a standard AmigaDOS pattern */
  34.  
  35. filterpat = "(comm/(#?bbs|ambos|fido|amiex|dlg|cnet|ums|uucp)|demo/#?)"
  36.  
  37. width=100         /* The default display width */
  38. maxhits=30         /* The default number of maximum hits */
  39. fsitenum=1         /* Your default Aminet findsite number (Select one of those below) */
  40.  
  41. /* END OF CONFIGURATION VARIABLES - DO NOT CHANGE ANYTHING BELOW */
  42.  
  43.  
  44. findsite.1 = "ftp.wustl.edu"
  45. findsite.2 = "amiga.icu.net.ch"
  46. findsite.3 = "haegar2.uni-paderborn.de"
  47.  
  48. portname = "FINDAMINET"
  49. amiftp_args = "PUBSCREEN " pubscreen
  50. found=0
  51. exact=0
  52. name = ''
  53.  
  54. if right(dldir,1) ~= ':' & right(dldir,1) ~= '/' then dldir = dldir||'/'
  55.  
  56. call LoadLibraries
  57.  
  58. parse arg cmds
  59.  
  60. call ParseCmds cmds
  61.  
  62. if name = "" then do
  63.     cmds = rtgetstring(,"Please enter search keyword","Find which file?",,"rt_pubscrname="pubscreen )
  64.     if cmds = "" then exit
  65.     call ParseCmds cmds
  66.     if name = "" then exit
  67. end
  68.  
  69. /*say name
  70. say maxhits width findsite.fsitenum portname sitename exact */
  71.  
  72. address value portname
  73.  
  74. if ~showlist(H,'TCP') then address command 'mount TCP: from amitcp:devs/inet-mountlist'
  75. if ~showlist(H,'TCP') then address command 'mount TCP:'
  76. if showlist(H,'TCP') then do
  77.     name=strip(name)
  78.  
  79.     newfile = 'T:findfile' || pragma('ID') || '.guide'
  80.     if ~open( fnewfile, newfile, 'W' ) then exit 
  81.  
  82.         call writeln( fnewfile, '@database Findfile' )
  83.     call writeln( fnewfile, '@node Main "Searching for '''name''' from 'findsite.fsitenum' - using site' sitename'"' )
  84.     call writeln( fnewfile, '@{" Search for a new file " rx "Find.AmiFTP -s'sitename' -p'portname' -f'fsitenum'"}')
  85.     call writeln( fnewfile, '' )
  86.  
  87.     if open(1,'tcp:'||findsite.fsitenum||'/1848',w) then do
  88.         call writeln(1,'max 'maxhits)
  89.         call writeln(1,'width 'width)
  90.         if exact then call writeln(1,'find "'name'"')
  91.         else
  92.             call writeln(1,'find 'name)
  93.         call writeln(1,'quit')
  94.         do until eof(1)
  95.             text=readln(1)
  96. /*             say text */
  97.             select
  98.                 when left(text,6)='*** No' then call writeln( fnewfile, 'No matches found.')
  99.                 when left(text,6)='*** Ad' then do
  100.                     call writeln( fnewfile, '')
  101.                     call writeln( fnewfile, 'Additional Matches Found.')
  102.                     call writeln( fnewfile, '')
  103.                 end
  104.                 when text = '' then foo = 1
  105.                 when text = 'Unknown command (? for help).' then foo = 1
  106.                 otherwise
  107.                     call WriteLine text
  108.             end
  109.         end
  110.         call writeln( fnewfile, '@endnode' )
  111.         call close( fnewfile )
  112.         if found then call InitAmiFTP
  113.         call shownode(pubscreen,newfile,'Main',0,0)
  114.         call delete( newfile )
  115.     end
  116.     else call rtezrequest( "Error opening TCP:","Ok","Find requester","rt_pubscrname="pubscreen )
  117. end
  118. else call rtezrequest( "You need AmiTCP installed in the proper directories, or mount TCP:","Ok","Find requester","rt_pubscrname="pubscreen )
  119.  
  120. exit
  121.  
  122. LoadLibraries:
  123.     if ~show(l, 'rexxsupport.library') then
  124.         if ~addlib('rexxsupport.library', 0, -30, 0) then exit 50
  125.  
  126.     if ~show(l, 'rexxdossupport.library') then
  127.         if ~addlib('rexxdossupport.library', 0, -30, 0) then exit 50
  128.  
  129.     if ~show(l, 'rexxreqtools.library') then
  130.         if ~addlib('rexxreqtools.library', 0, -30, 0) then exit 50
  131.  
  132.     if ~show(l, 'amigaguide.library') then
  133.         if ~addlib('amigaguide.library', 0, -30, 0) then exit 50
  134.  
  135. return
  136.  
  137. /* This procedure is modified from the one in Browse.DaFTP */
  138. InitAmiFTP: procedure expose portname amiftp_args sitename AmiFTP_bin
  139.     if ~exists(AmiFTP_bin) then AmiFTP_bin = "AmiFTP"
  140.         if ~show( 'P', portname ) then do
  141.             address command 'Run >NIL:' AmiFTP_bin '>NIL:' amiftp_args 'PORTNAME' portname
  142.             address command 'WaitForPort' portname
  143.             if RC ~= 0 then do
  144.                  call rtezrequest("Could not start AmiFTP",,"Find requester","rt_pubscrname="pubscreen )
  145.                 exit 20
  146.         end
  147.     end
  148.     'DEACTIVATE'
  149.     'GETATTR STEM STAT'
  150.     if STAT.CONNECTED ~= 1 then 
  151.         call ConnectSite
  152.     else if STAT.HOST ~= sitename then do
  153.         'DISCONNECT'
  154.         call ConnectSite
  155.     end    
  156. return
  157.  
  158. ConnectSite: procedure expose sitename
  159.     'SETATTR HOST' sitename 'PORT 21'     
  160.     'CONNECT NOSCAN'
  161.     'SETATTR REMOTEDIR /pub/aminet'
  162. return
  163.  
  164. WriteLine: 
  165.     parse var text file.name file.dir file.size file.age file.desc
  166.     astpos = pos('*', file.age)
  167.     if fsitenum = 3 then do
  168.         file.desc = ' ' || file.age file.desc 
  169.         file.age = ''
  170.     end
  171.     else if astpos ~= 0 then do 
  172.         file.desc = ' ' || substr(file.age, astpos + 1) || file.desc
  173.         file.age = left(file.age, astpos - 1)
  174.     end
  175.     dot = lastpos(".", file.name)
  176.     if ~found then do
  177.         found = 1
  178.         call writeln( fnewfile, " FILE                   DIR        SIZE AGE  DESCRIPTION" )
  179.     end
  180.     if ~filtercrap | ~MatchPattern(filterpat, file.dir, "NoCase") then do
  181.         if (dot > 0) then
  182.             file.readme = left(file.name, dot) || 'readme'
  183.         else
  184.               file.readme = file.name'.readme'
  185.         file.desc = translate(file.desc,'''','"')
  186.         if file.name ~= "" then do
  187.         select
  188.         when viewmethod = 'processfile' then
  189. /*name*/            lin = '@{"' left(file.name, 20, ' ') '" rxs "address '''portname''';''
  190. GET BIN /pub/aminet/'file.dir'/'file.name' LOCAL 'dldir||file.name''';
  191. address command ''rexx:processfile.rexx 'dldir||file.name'''"}'
  192.         when viewmethod = 'builtin' then
  193. /*name*/            lin = '@{"' left(file.name, 20, ' ') '" rxs "address '''portname''';''
  194. VIEW BIN /pub/aminet/'file.dir'/'file.name'''"}'
  195.         otherwise
  196. /*name*/            lin = '@{"' left(file.name, 20, ' ') '" rxs "address '''portname''';''
  197. GET BIN /pub/aminet/'file.dir'/'file.name' LOCAL 'dldir||file.name'''"}'
  198.         end
  199. /*dir*/                lin = lin left(file.dir, 10, ' ')
  200. /*size*/            lin = lin right(file.size,4, ' ')
  201. /*age */            lin = lin right(file.age,3, ' ')
  202. /*desc*/            lin = lin '@{"'file.desc '" rxs "address '''portname''';''
  203. GET BIN /pub/aminet/'file.dir'/'file.readme' LOCAL t:'file.readme''';
  204. call shownode('''pubscreen''',''t:'file.readme''',''Readme'',0,0)"}'
  205.  
  206.         call writeln( fnewfile, lin )
  207.         end
  208.     end
  209.  
  210. return
  211.  
  212. ParseCmds:
  213.     parse var cmds
  214. /*    say cmds */
  215.     do while word(cmds,words(cmds)) ~= ''
  216.         lw=word(cmds,words(cmds))
  217.         if left(word(cmds,words(cmds)),1)='-' then do
  218.             lc=upper(left(lw,2))
  219.             num=right(lw,length(lw)-2)
  220. /*            say num */
  221.             if lc='-M' then maxhits=num 
  222.             if lc='-S' then sitename=num 
  223.             if lc='-P' then portname=num 
  224.             if lc='-W' then width=num 
  225.             if lc='-E' then exact=1
  226.             if lc='-C' & (num = 0 | num = 1) then filtercrap = num
  227.             if lc='-F' & (num>0 & num<4) then fsitenum = num
  228.         end
  229.         else 
  230.             name = lw name
  231.         cmds=reverse(cmds)
  232.         parse var cmds .' 'cmds
  233.         cmds=reverse(cmds)
  234.     end
  235.     if index(name,'"')>0 then do
  236.         parse var name '"'name'"'
  237.     end
  238. return
  239.  
  240.